import gui from '@/lib/gui.js';

function slideUp(page, animationId, offset, callback){
	var time = 500;
	var animationInit = uni.createAnimation({
		duration: 0,
	    timingFunction: 'ease',
	    delay: 0
	});
	animationInit.translateY(offset).step();
	page[animationId]=animationInit.export();
	setTimeout(function () {
	    var animation = uni.createAnimation({
	      duration: time,
	      timingFunction: 'ease',
	      delay: 0
	    });
	    animation.translateY(0).step();
		page[animationId]=animation.export();
		if(callback!=null){
			setTimeout(()=>{
				callback();
			}, time);
		}
	}, 0)
}

function rotatePositive(page, animationId, callback){
	var animationInit = uni.createAnimation({
		duration: 100,
	    timingFunction: 'linear'
	});
	
	var index = 0;
	var intervalId = setInterval(function() {
		animationInit.rotate(45*index).step();
		page[animationId] = animationInit.export();
		index++;
		if(index>4){
			clearInterval(intervalId);
			if(callback!=null){
				callback();
			}
		}
	}, 100)
}

function rotateNegative(page, animationId, callback){
	var animationInit = uni.createAnimation({
		duration: 100,
	    timingFunction: 'linear'
	});
	
	var index = 0;
	var intervalId = setInterval(function() {
		animationInit.rotate(-45*index).step();
		page[animationId] = animationInit.export();
		index++;
		if(index>4){
			clearInterval(intervalId);
			if(callback!=null){
				callback();
			}
		}
	}, 100)
}

export default{
	slideUp,
	rotatePositive,
	rotateNegative
}
